var models = require('../../db/models')
var server = require('../server')
var db = require('../../db/connect')
var encrypt = require('../../libs/encrypt')
var jsonres = require('../../libs/jsonres')
var http = require('http');

var querystring = require('querystring');

function timedGetText(cb){
// const http = require("http")
const url = "http://dev.legendpoker.cn:8088/?playerid=13882231811&platform=%E5%BE%B7%E6%89%91%E5%9C%88"
http.get(url,(res)=>{
    var html ="";
    res.on("data",(data)=>{
        html+=data
    })

    res.on("end",()=>{
        console.log(html)
        cb(html)
    })

}).on("error",(e)=>{
    console.log(`获取数据失败: ${e.message}`)
})}
server.get('/api/records',function(req,res){

    timedGetText(function (html) {
        console.log(html)
       content=JSON.parse(html.toString());
    var p = req.query.platform;
    var u = req.query.mobile;
    var resBody = {
        platform: '', // 平台名称
        mobile: '',
        total: 0, // 手数
        inpoor: 1, // 入池率
        gains: 0, // 盈利
        winningRatio: 0, // 胜率
    };


        if (content.count!="") {
            resBody.platform = content.platform || p;
            resBody.mobile = content.mobile || u;
            resBody.total = content.count;
            resBody.inpoor = content.inpoor/content.count;
            resBody.gains = content.chips;
            resBody.winningRatio = content.winrate;
        }
        res.send(jsonres(200,'success',resBody))
    });

})
